package ee.az.test.convert;

import java.lang.reflect.Method;

import ee.az.test.convert.src.ASrc;
import ee.az.test.convert.src.BSrc;
import ee.az.test.convert.src.CSrc;
import ee.az.test.convert.src.Src;
import ee.az.test.convert.trgt.ATrgt;
import ee.az.test.convert.trgt.BTrgt;
import ee.az.test.convert.trgt.CTrgt;
import ee.az.test.convert.trgt.Trgt;

public class Converter {
	public static Trgt convert(Src src) throws Exception {
		try {
			Method method = Converter.class.getDeclaredMethod("convert", src.getClass());
			return (Trgt) method.invoke(null, src);
		} catch (NoSuchMethodException e) {
			System.err.println("Cannot convert " + src.getClass().getName());
			throw e;
		}
	}
	
	protected static ATrgt convert(ASrc src) {
		return new ATrgt();
	}
	protected static BTrgt convert(BSrc src) {
		return new BTrgt();
	}
	protected static CTrgt convert(CSrc src) {
		return new CTrgt();
	}
}
